//
// Created by liushuai on 2021/1/31.
//

#include "maxsumofSubarray.h"
int maxsumofSubarray(vector<int>& arr) {
    if(arr.empty())
        return 0;
    int current = arr[0];
    int result = current;
    for(int i=1;i<arr.size();){
        if(current>=result)
            result = current;
        if(current<0){
            current = arr[i];
            i+=1;
        }
        else{
            current += arr[i];
            i+=1;
        }

    }
    return current;
}